
/**
* @Title: ContentServiceImpl.java
* @Package com.leetone.portal.service.impl
* @Description: 【】
* @date 2018年3月17日 下午7:31:17
* @version V1.0
* @Company: 上海
* @author:[谭磊][leetone123@163.com]
*/

package com.leetone.portal.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.leetone.pojo.Content;
import com.leetone.portal.service.ContentService;
import com.leetone.utils.HttpClientUtil;
import com.leetone.utils.JsonUtils;
import com.leetone.utils.TaotaoResult;

/**
* @ClassName: ContentServiceImpl
* @Description: 【】
* @date 2018年3月17日 下午7:31:17
* @Company: 上海
* @author:[谭磊][leetone123@163.com]
*/
@Service
public class ContentServiceImpl implements ContentService{
	@Value("${baseUrl}")
	private String baseUrl;
	@Value("${contentListMethod}")
	private String contentListMethod;
	
	@Override
	public String getContentList() {
		String result = HttpClientUtil.doGet(baseUrl+contentListMethod);
		//把字符串解析成TaotaoResult
		try {
			TaotaoResult taotaoResult = TaotaoResult.formatToList(result, Content.class);
			//取内容列表
			List<Content> list =(List<Content>) taotaoResult.getData();
			List<Map> resultList = new ArrayList<>();
			Map map = new HashMap<>();
			//创建一个jsp页面要求的pojo列表
			for(Content content : list)
			{
				map.put("src", content.getPic());
				map.put("height", 240);
				map.put("width", 670);
				map.put("srcB", content.getPic2());
				map.put("widthB", 550);
				map.put("heightB", 240);
				map.put("href", content.getUrl());
				map.put("alt", content.getSubTitle());
				resultList.add(map);
			}
			return JsonUtils.objectToJson(resultList);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	
}
